home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 6.8 KB | 204 lines | [TEXT/CCL2] |
- ;;; simple-scatter-plot.lisp
- ;;;
- ;;; Paul McCartney, Spring 1992
- ;;;
- ;;; Copyright © 1992 Paul McCartney. All Rights Reserved.
- ;;;
- ;;; Washington University Medical Informatics Training Program
- ;;;
- ;;; DESCRIPTION:
- ;;;
- ;;; This file is a sample implementation of a basic scatter plot. It demostrates
- ;;; the "number-line-view" and "scatter-plot-view" that are provided.
- ;;;
- ;;; USE:
- ;;;
- ;;; See the end of this file for sample window creation.
- ;;;
- ;;; HISTORY:
- ;;;
- ;;; 6/30/92 Created. - PM
- ;;;
-
- (in-package :cl-user)
-
- (require :graphics-tools)
- (require :number-line-view)
- (require :scatter-plot-view)
- (require :pop-up-view)
- (require :quickdraw)
-
-
- ;;;;
- ;;;; POP UP VIEW
- ;;;;
-
- (defun draw-point-info (puv size data)
- (declare (ignore size))
- (let ((x (first data))
- (y (second data)))
- (with-fore-color *blue-color*
- (#_MoveTo 10 18)
- (format puv "Point:"))
- (with-fore-color *light-blue-color*
- (#_MoveTo 50 18)
- (format puv "(~s, ~s)" x y)) ))
-
-
- (defvar *pop-up-view*)
- (setf *pop-up-view*
- (make-instance 'pop-up-view
- :pop-up-view-size #@(120 30)
- :pop-up-view-draw-fn #'draw-point-info
- :color-list (list
- :background *yellow-color*
- :frame *dark-green-color*
- :shadow *green-color*)))
-
-
- ;;;;
- ;;;; SCATTER PLOT POINT SPECIALIZATION
- ;;;;
-
- (defclass specialized-point (scatter-plot-point)
- ((color :initarg :color :accessor color)
- (outline-color :initarg :outline-color :accessor outline-color)) )
-
-
- (defmethod draw-scatter-plot-point ((point specialized-point) view topleft bottomright)
- (with-fore-color (color point)
- (paint-oval view topleft bottomright))
- (with-fore-color (outline-color point)
- (frame-oval view topleft bottomright)) )
-
-
- ;;;;
- ;;;; SIMPLE SCATTER PLOT
- ;;;;
-
- (defclass simple-scatter-plot (window)
- ((vertical-scroll-width :initarg :vertical-scroll-width
- :accessor vertical-scroll-width)
- (horizontal-scroll-width :initarg :horizontal-scroll-width
- :accessor horizontal-scroll-width)
- (window-grow-rect :accessor window-grow-rect
- :initform (make-record :rect :topleft #@(315 220)
- :bottomright #@(800 600))))
- (:default-initargs
- :window-title "Simple Scatter Plot"
- :view-position #@(50 50)
- :view-size #@(500 300)
- :window-type :document-with-grow
- :vertical-scroll-width 50
- :horizontal-scroll-width 50
- :color-p t) )
-
-
- (defmethod initialize-instance ((view simple-scatter-plot) &rest initargs)
- (apply #'call-next-method view initargs)
- (set-back-color view *black-color*)
- (add-scatter-plot-views view)
- (set-view-sizes-and-positions view) )
-
-
- (defmethod add-scatter-plot-views ((view simple-scatter-plot))
- (add-subviews view
- (make-instance 'scatter-plot-view
- :view-nick-name 'scatter-plot
- :click-on-point-function
- #'(lambda (view data) (puv-display *pop-up-view* (view-container view) data) ))
-
- (make-instance 'number-line-vertical-view
- :title '("Y" " " "A" "X" "I" "S")
- :dialog-item-action #'(lambda (item) (arrange-scatter-plot (view-container item)))
- :start 0
- :end 600
- :min-value 0
- :max-value 1000
- :color-list (list :title *orange-color* :frame *orange-color*
- :numbers *yellow-color*)
- :title-font-spec '("monaco" 9 :bold)
- :mark-font-spec '("courier" 9)
- :view-nick-name 'vertical-scale-bar
- :tick-mark-inc-fn #'(lambda (scale) (find-pixel-increment-v scale 3/10 5)))
-
- (make-instance 'number-line-horizontal-view
- :title '("X AXIS")
- :dialog-item-action #'(lambda (item) (arrange-scatter-plot (view-container item)))
- :start 0
- :end 72
- :min-value 0
- :max-value 300
- :color-list (list :title *orange-color* :frame *orange-color*
- :numbers *yellow-color*)
- :title-font-spec '("monaco" 9 :bold)
- :mark-font-spec '("courier" 9)
- :view-nick-name 'horizontal-scale-bar
- :tick-mark-inc-fn #'(lambda (scale) (find-pixel-increment-h scale 3/4 2)))
-
- (make-instance 'static-text-dialog-item
- :dialog-item-text "Drag number lines to scroll. Shift-Drag number lines to rescale. Click on points to inspect."
- :view-position #@(0 0)
- :view-font '("times" 12 :plain)
- :part-color-list (list :text *white-color*))
- ))
-
-
- (defmethod set-view-sizes-and-positions ((view simple-scatter-plot))
- (let ((scatter-plot (view-named 'scatter-plot view))
- (vertical-scale (view-named 'vertical-scale-bar view))
- (horizontal-scale (view-named 'horizontal-scale-bar view)) )
- (set-view-position vertical-scale #@(0 15))
- (set-view-size vertical-scale
- (vertical-scroll-width view)
- (- (point-v (view-size view)) (vertical-scroll-width view) 15))
- (set-view-position horizontal-scale
- (vertical-scroll-width view)
- (+ (point-v (view-size vertical-scale))
- (point-v (view-position vertical-scale))))
- (set-view-size horizontal-scale
- (- (point-h (view-size view)) (vertical-scroll-width view))
- (horizontal-scroll-width view))
- (set-view-position scatter-plot (horizontal-scroll-width view) 15)
- (set-view-size scatter-plot
- (point-h (view-size horizontal-scale))
- (point-v (view-size vertical-scale)))
- (arrange-scatter-plot view) ))
-
-
- (defmethod set-view-size ((view simple-scatter-plot) h &optional v)
- (call-next-method view h v)
- (set-view-sizes-and-positions view))
-
-
- (defmethod arrange-scatter-plot ((view simple-scatter-plot))
- (let ((scatter-plot (view-named 'scatter-plot view))
- (vertical-scale (view-named 'vertical-scale-bar view))
- (horizontal-scale (view-named 'horizontal-scale-bar view)) )
- (set-scatter-plot-range scatter-plot
- (number-line-start horizontal-scale)
- (number-line-end horizontal-scale)
- (number-line-start vertical-scale)
- (number-line-end vertical-scale)) ))
-
- ;;;;
- ;;;; EXTERNAL DATA I/O
- ;;;;
-
- (defmethod add-data ((view simple-scatter-plot) events)
- (let ((plot (view-named 'scatter-plot view)))
- (add-scatter-plot-points plot events 'specialized-point t)
- (dolist (point (scatter-plot-points plot))
- (setf (color point)
- (nth (random 4)
- (list *red-color* *yellow-color* *green-color* *light-blue-color*)))
- (setf (outline-color point) (change-brightness (color point) 1.7))) ))
-
-
- #|
- ; Example: Create the simple scatter plot (assuming *sample-data* has data)
-
- (let ((w (make-instance 'simple-scatter-plot :window-show nil)))
- (add-data w *sample-data*)
- (window-select w))
- |#